import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";

export enum MonthlyCardType {
  SMALL = 38, // 小月卡
  LARGE = 98, // 大月卡
}

export enum MonthlyCardStatus {
  INACTIVE = 0, // 未激活
  ACTIVE = 1, // 已激活
  EXPIRED = 2, // 已过期
}

@Entity("monthly_cards")
@ManualTimestamp()
export class MonthlyCardEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column("int", { name: "characterId", comment: "角色ID" })
  characterId!: number;

  @Column("int", { comment: "月卡类型：38-小月卡，98-大月卡" })
  cardType!: MonthlyCardType;

  @Column("int", {
    default: 0,
    comment: "月卡状态：0-未激活，1-已激活，2-已过期" })
  status!: MonthlyCardStatus;

  @Column("int", {
    default: 0,
    comment: "月卡阶段：0-初始，1-已购买，2-已激活" })
  stage!: number;

  @Column("int", { default: 0, comment: "是否已过期：0-未过期，1-已过期" })
  over!: number;

  @Column("datetime", { comment: "购买时间" })
  purchasedAt!: Date;

  @Column("datetime", { comment: "激活时间" })
  activatedAt!: Date;

  @Column("datetime", { comment: "到期时间" })
  expiresAt!: Date;

  @Column("datetime", { comment: "最后领取每日奖励时间" })
  lastDailyRewardAt!: Date;

  @Column("int", {
    default: 0,
    comment: "今日是否已领取每日奖励：0-未领取，1-已领取" })
  todayRewardClaimed!: number;

  @Column("int", { default: 0, comment: "连续领取天数" })
  consecutiveDays!: number;

  @Column("int", { default: 0, comment: "总领取天数" })
  totalDays!: number;

  @Column("int", { default: 0, comment: "购买价格（银两）" })
  price!: number;

  @Column("varchar", { length: 200, comment: "备注" })
  remark!: string;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", { name: "updated_at", nullable: true, comment: "更新时间" })
  updated_at!: Date | null;

  // 关联关系
  @ManyToOne(() => CharacterEntity, (character) => character.monthlyCards)
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;
}
